var uploader = Qiniu.uploader({
    runtimes: 'html5,flash,html4',
    browse_button: 'img_upload',
    container: 'upload_box',
    drop_element: 'upload_box',
    max_file_size: '100mb',
    flash_swf_url: 'js/plupload/Moxie.swf',
    dragdrop: true,
    chunk_size: '4mb',
    uptoken_url: '/user/token.json',
    unique_names: false,
    save_key: false,
    domain: 'http://codekiller.qiniudn.com/',
    auto_start: true,
	filters: {
		mime_types : [
			{ title : "Image files", extensions : "jpg,gif,png" },
			// { title : "Zip files", extensions : "zip" }
		]
	},
    init: {
        'FilesAdded': function(up, files) {
        },
        'BeforeUpload': function(up, file) {
        },
        'UploadProgress': function(up, file) {
            upload_progress(file.percent);
        },
        'UploadComplete': function() {
        },
        'FileUploaded': function(up, file, info) {
			var obj = JSON.parse(info);
			var link = up.getOption('domain') + obj.key;
			textarea_add_source_link(link);
            upload_progress(0);
        },
        'Error': function(up, err, errTip) {
            alert(errTip);
        },
		'Key': function(up, file) {
            var filename = file.name.split('.')[0];
            var myDate = new Date();
            var y = myDate.getFullYear() % 2000;
            var F = ('0' + (myDate.getMonth() + 1)).substr(-2);
            var d = ('0' + myDate.getDate()).substr(-2);
            var H = ('0' + myDate.getHours()).substr(-2);
            var i = ('0' + myDate.getMinutes()).substr(-2);
            var s = ('0' + myDate.getSeconds()).substr(-2);
            return filename + '_' + getCookie('uid') + y + F + d + H + i + s;
		}
    }
});
